﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Person
/// </summary>
public class Person
{
    private string email = null;
    private string status = null;
    private string first_name = null;
    private string last_name = null;
    private string academical_degree = null;
    private string phone = null;
    private string street = null;
    private string city = null;
    private string postal_code = null;
    private string account = null;
    private string activation_code = null;
    private Dictionary<Configuration.PersonAttributes, string> dic;

    public string Email { get { return this.email; } set { this.email = value; } }
    public string Status { get { return this.status; } set { this.status = value; } }
    public string FirstName { get { return this.first_name; } set { this.first_name = value; } }
    public string LastName { get { return this.last_name; } set { this.last_name = value; } }
    public string AcademicalDegree { get { return this.academical_degree; } set { this.academical_degree = value; } }
    public string Phone { get { return this.phone; } set { this.phone = value; } }
    public string Street { get{ return this.street; } set { this.street = value; } }
    public string City { get { return this.city; } set { this.city = value; } }
    public string PostalCode { get {return this.postal_code; } set { this.postal_code = value; } }
    public string Account { get { return this.account; } set { this.account = value; } }  
    public string ActivationCode { get { return this.activation_code; } set {this.activation_code = value; } }


    public Person() { }

    public Person(string email, string status, string first_name, string last_name,
                  string accademical_degree, string phone, string street, string city,
                  string postal_code, string account, string activation_code
                 )
    {
        this.email = email;
        this.status = status;
        this.first_name = first_name;
        this.last_name = last_name;
        this.academical_degree = accademical_degree;
        this.phone = phone;
        this.street = street;
        this.city = city;
        this.postal_code = postal_code;
        this.account = account;
        this.activation_code = activation_code;
    }

    public Person(Dictionary<Configuration.PersonAttributes, string> values)
    {
        foreach ( Configuration.PersonAttributes att in values.Keys)
            switch (att)
            {
                case Configuration.PersonAttributes.email: this.email = values[att];
                                                    break;
                case Configuration.PersonAttributes.status: this.status = values[att];
                                                     break;
                case Configuration.PersonAttributes.first_name: this.first_name = values[att];
                                                        break;
                case Configuration.PersonAttributes.last_name: this.last_name = values[att];
                                                        break;
                case Configuration.PersonAttributes.academical_degree: this.academical_degree = values[att];
                                                                 break;
                case Configuration.PersonAttributes.phone: this.phone = values[att];
                                                    break;
                case Configuration.PersonAttributes.street: this.street = values[att];
                                                     break;
                case Configuration.PersonAttributes.city: this.city = values[att];
                                                    break;
                case Configuration.PersonAttributes.postal_code: this.postal_code = values[att];
                                                          break;
                case Configuration.PersonAttributes.account: this.account = values[att];
                                                      break;
                case Configuration.PersonAttributes.activation_code: this.activation_code = values[att];
                                                              break;
            }
    }

    public static Person newInstance(string[] values)
    {
        if (values.Length != Configuration.PersonAttributesCount)
            return null;

        return new Person(values[0], values[1], values[2], values[3], values[4], values[5],
                          values[6], values[7], values[8], values[9], values[10]
                         );
    }

    public Dictionary<Configuration.PersonAttributes, string> toDictionary()
    {
        dic = new Dictionary<Configuration.PersonAttributes, string>();
        dic.Add(Configuration.PersonAttributes.email, this.email);
        dic.Add(Configuration.PersonAttributes.status, this.status);
        dic.Add(Configuration.PersonAttributes.first_name, this.first_name);
        dic.Add(Configuration.PersonAttributes.last_name, this.last_name);
        dic.Add(Configuration.PersonAttributes.academical_degree, this.academical_degree);
        dic.Add(Configuration.PersonAttributes.phone, this.phone);
        dic.Add(Configuration.PersonAttributes.street, this.street);
        dic.Add(Configuration.PersonAttributes.city, this.city);
        dic.Add(Configuration.PersonAttributes.postal_code, this.postal_code);
        dic.Add(Configuration.PersonAttributes.account, this.account);
        dic.Add(Configuration.PersonAttributes.activation_code, this.activation_code);
        return dic;
    }

    public string[] toArray() 
    {
        return this.toDictionary().Values.ToArray<string>();

    }
}
